package com.esun.common.enums;

import org.apache.commons.lang.StringUtils;

/**
 * 基础错误码枚举
 *
 * @author john.xiao
 * @date 2021/3/11 11:06
 */
public enum Message {

	//基础错误码。code 从10001开始,10000为请求成功
	QUERY_SUCCESS("10000", "请求成功"),
	QUERY_ERROR("10001", "请求失败"),
	EXISTED("10002", "已存在"),
	NOT_EXIST("10003", "不存在"),
	LOGIN_FAILED("10004","登录失败，账号不存在或者密码错误"),
	SECURITY_CONTROLLER_NOT_EXIST("10005","不存在相应的安全控制方案"),
	PASSWORD_IS_EMPTY("10006","密码为空"),
	PASSWORD_LENGTH_ILLEGAL("10007","密码长度不合法"),
	PASSWORD_NUM_LENGTH_ILLEGAL("10008","密码最低数字长度不合法"),
	PASSWORD_UPPERCASE_ILLEGAL("10009","密码格式不正确，密码必须含有大写字母"),
	PASSWORD_LOWERCASE_ILLEGAL("10010","密码格式不正确，密码必须含有小写字母"),
	PASSWORD_NUM_ILLEGAL("10011","密码格式不正确，密码必须含有数字"),
	PASSWORD_SPECIAL_CHARACTER_ILLEGAL("10012","密码格式不正确，密码必须含有特殊字符");
	

	Message(String code, String info) {
		this.code = code;
		this.info = info;
	}

	public static String getInfoByCode(String code) {
		if (StringUtils.isNotEmpty(code)) {
			Message[] messages = Message.values();
			for (Message message : messages) {
				if (message.getCode().equals(code)) {
					return message.getInfo();
				}
			}
		}
		return null;
	}

	private final String code;


	private final String info;

	public String getCode() {
		return code;
	}


	public String getInfo() {
		return info;
	}
}
